
package com.dhcc.sds.api.controller;

import cn.hutool.core.date.DateTime;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.cdc.busi.entity.CdcEpisodeEntity;
import com.dhcc.cdc.busi.service.ICdcEpisodeService;
import com.dhcc.cdc.busi.service.ICdcHospitalService;
import com.dhcc.cdc.sys.cache.config.CdcConfigCache;
import com.dhcc.cdc.sys.service.IConfigurationService;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.ArrayUtil;
import com.dhcc.core.framework.util.CommonUtil;
import com.dhcc.sdc.busi.service.ISdcBusiQcTriggeredService;
import com.dhcc.sdc.busi.service.ISdcHomeIndexService;
import com.dhcc.sds.api.service.IDocApiService;
import com.dhcc.sds.base.cache.qcentity.QcEntityCache;
import com.dhcc.sds.base.entity.SdsQcentityEntity;
import com.dhcc.sds.base.service.ISdsCommonService;
import com.dhcc.sds.base.service.ISdsQcentityService;
import com.dhcc.sds.busi.dto.AnalysisCaseDto;
import com.dhcc.sds.busi.entity.SdsQcincaseEntity;
import com.dhcc.sds.busi.service.IAnalysisSdsIndstaService;
import com.dhcc.sds.busi.service.IAnalysisSdsMstaService;
import com.dhcc.sds.busi.service.ISdsQcincaseService;
import com.dhcc.sds.util.DateUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;

/**
 *
 * @Description:sds与医生站对接代码
 * @ClassName:  DocApiController
 * @date:2021年11月17日 下午5:26:14
 * @author: sunyingjie
 * @Version 1.0 DHC-SDS
 */
@Controller
@RequestMapping("${sys.apiPath}")
public class DocApiController {

    private String PREFIX = "/backend/sds/docapi/";

    @Autowired
    private IDocApiService docApiService;

    @Autowired
    private IConfigurationService configurationService;

    @Autowired
    private ISdsQcincaseService sdsQcincaseService;
    @Autowired
    private ICdcEpisodeService cdcEpisodeService;
    @Autowired
    private ISdsQcentityService sdsQcentityService;
    @Autowired
    private ISdcHomeIndexService sdcHomeIndexService;
    @Autowired
    private ISdcBusiQcTriggeredService sdcBusiQcTriggeredService;
    @Autowired
    private ICdcHospitalService cdcHospitalService;
    @Autowired
    private ISdsCommonService sdsCommonService;
    @Autowired
    private IAnalysisSdsMstaService analysisSdsMstaService;
    @Autowired
    private IAnalysisSdsIndstaService analysisSdsIndstaService;

    /**
     * @Description: 临床医生填报页面
     * @Title: fillByDoctor
     * @param model
     * @return: String
     * @author: syj
     * @date:2021年11月17日 下午11:29:15
     */
    @RequestMapping(value ="/fillByDoctor")
    @ApiOperation(value = "医生填报页面")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "userId", value = "登陆用户Id", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "wardId", value = "病区Id", required = false, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "locId", value = "科室Id", required = false, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "type", value = "类型1用户2病区3科室", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "Role", value = "当前用户的角色类别", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "userName", value = "登陆用户名称", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "hisWebIp", value = "HISWebIp", required = true, dataType = "String")
    })
    public String fillByDoctor(@RequestParam String userId,@RequestParam String wardId,@RequestParam String locId,
                               @RequestParam String type,@RequestParam String Role,@RequestParam String userName,
                               @RequestParam String hisWebIp, Model model) {

        DateTime lastDay = new DateTime();
        DateTime firstday = DateUtil.getDateByDay(lastDay, -30);

        model.addAttribute("startDate", firstday);
        model.addAttribute("endDate", lastDay);
        // 单病种医生是否可以直接上报配置
        String formCheckType = CdcConfigCache.me().getValueByKey("SDS", "SDFormCheckType");
        // 是否启用过程质控
        String ipqcConfig = CdcConfigCache.me().getValueByKey("SDS", "EnableIPQCModule");
        JSONObject statusMap = docApiService.getStatusMapByType("SDQCMrStatus");
        model.addAttribute("formCheckType", formCheckType);
        model.addAttribute("enableIPQC", ipqcConfig);
        model.addAttribute("statusMap", statusMap);
        model.addAttribute("userId", userId);
        model.addAttribute("userName", userName);
        model.addAttribute("wardId", wardId);
        model.addAttribute("locId", locId);
        model.addAttribute("type", type);
        model.addAttribute("Role", Role);
        model.addAttribute("hisWebIp", hisWebIp);
        // 临床科主任安全组id
        String deptGroup = CdcConfigCache.me().getValueByKey("SDS", "HisDeptDirGroupID");
        String checkPerm = "0";
        if (CommonUtil.equals(Role, deptGroup)) {
            checkPerm = "1";
        }
        model.addAttribute("checkPerm", checkPerm);

        return PREFIX + "sdsfillbydoctor.html";
    }

    /**
     * 获取病种入组病例列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/fillByDoctor/list")
    @ResponseBody
    public Object list(@RequestParam Map<String, Object> params) {
        Page<SdsQcincaseEntity> page = new PageFactory<SdsQcincaseEntity>().defaultPage();
        List<SdsQcincaseEntity> result = this.docApiService.page(page,params);
        page.setRecords((List<SdsQcincaseEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 获取质控病种字典列表(不分页)
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/fillByDoctor/qryQCEntity")
    @ResponseBody
    public Object qryQCEntity(@RequestParam Map<String, Object> params) {
        return this.docApiService.listByDate(params);
    }

    /**
     * @Description: 出院病例查询页面
     * @Title: doctDisposal
     * @param model
     * @return: String
     * @author: syj
     * @date:2021年11月17日 下午11:29:15
     */
    @RequestMapping(value ="/patientlist")
    @ApiOperation(value = "出院病例查询页面")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "userId", value = "登陆用户Id", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "wardId", value = "病区Id", required = false, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "locId", value = "科室Id", required = false, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "type", value = "类型1用户2病区3科室", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "Role", value = "当前用户的角色类别", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "userName", value = "登陆用户名称", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "hisWebIp", value = "HISWebIp", required = true, dataType = "String")
    })
    public String patientList(@RequestParam String userId,@RequestParam String wardId,@RequestParam String locId,
                               @RequestParam String type,@RequestParam String Role,@RequestParam String userName,
                               @RequestParam String hisWebIp, Model model) {
        // 是否启用过程质控
        String ipqcConfig = CdcConfigCache.me().getValueByKey("SDS", "EnableIPQCModule");
        model.addAttribute("enableIPQC", ipqcConfig);
        model.addAttribute("userId", userId);
        model.addAttribute("userName", userName);
        model.addAttribute("wardId", wardId);
        model.addAttribute("locId", locId);
        model.addAttribute("type", type);
        model.addAttribute("Role", Role);
        model.addAttribute("hisWebIp", hisWebIp);

        return PREFIX + "sdspatientlist.html";
    }

    /**
     * 跳转到表单填报页面
     */
    @RequestMapping(value="/formFilling")
    @ApiOperation(value = "医生表单页面")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "EpisodeID", value = "登陆用户Id", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "LocID", value = "科室Id", required = false, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "UserID", value = "登陆用户名称ID", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "Role", value = "当前用户的角色类别", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "UserName", value = "登陆用户名称", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "mrListId", value = "入组记录ID", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "msgDetailsId", value = "信息记录ID", required = true, dataType = "String")
    })
    public Object formFilling(@RequestParam String EpisodeID,@RequestParam String LocID,@RequestParam String UserID,
                              @RequestParam String Role,@RequestParam String UserName,@RequestParam String mrListId,
                              @RequestParam String msgDetailsId, Model model) {

        // 查询入组详细
        SdsQcincaseEntity mrEntity = sdsQcincaseService.selectById(mrListId);
        // 查询病种详细
        SdsQcentityEntity qcEntity = QcEntityCache.me().getQcEntityById(mrEntity.getEntityId());
        // 单病种医生是否可以直接上报配置
        String formCheckType = CdcConfigCache.me().getValueByKey("SDS", "SDFormCheckType");
        // 病历浏览路径
        String EMRPagePath = CdcConfigCache.me().getValueByKey("SDS", "EMRPagePath");
        // 单病种上报表单是否显示病历溯源
        String isShowDataTrace = CdcConfigCache.me().getValueByKey("SDS", "SDIsShowSourceData","N");
        // 是否合并上报流程
        String isMergeReport = CdcConfigCache.me().getValueByKey("SDS", "SDIsMergeReport", "N");
        // 临床科主任安全组id
        String deptGroup = CdcConfigCache.me().getValueByKey("SDS", "HisDeptDirGroupID");
        String checkPerm = "0";
        if (CommonUtil.equals(Role, deptGroup)) {
            checkPerm = "1";
        }
        model.addAttribute("execUser", UserName);
        model.addAttribute("execUserId", UserID);
        model.addAttribute("mrListId", mrListId);
        model.addAttribute("entityId", mrEntity.getEntityId());
        model.addAttribute("episodeId", mrEntity.getEpisodeId());
        model.addAttribute("formCheckType", formCheckType);
        model.addAttribute("checkPerm", checkPerm);
        model.addAttribute("msgDetailsId", msgDetailsId);
        model.addAttribute("EMRPagePath", EMRPagePath);
        model.addAttribute("isShowSourceData", isShowDataTrace);
        model.addAttribute("isMergeReport", isMergeReport);
        return "/backend/sds/sdsqcformshow/" + qcEntity.getAbbrev() + ".html";
    }

    @RequestMapping(value = "/getadmxcode")
    @ResponseBody
    public Object getadmxcode(@RequestParam Map<String, Object> params){
        CdcEpisodeEntity paadm = new CdcEpisodeEntity();
        Long mrlistId =Long.valueOf(params.get("mrListId").toString());
        SdsQcincaseEntity mrList = sdsQcincaseService.selectById(mrlistId);
        if (mrList!=null) {
            paadm = cdcEpisodeService.selectById(mrList.getEpisodeId());
        }
        return paadm;
    }

    @RequestMapping("/departhome")
    public String home(@RequestParam Map<String, Object> map, Model model) {
        //获取病种
        JSONArray entityMap = sdsQcentityService.getUpEntityMap();

        model.addAttribute("entityMap", entityMap);
        model.addAttribute("departCode", map.get("departCode"));
        model.addAttribute("departDesc", map.get("departDesc"));
        model.addAttribute("drgCode", map.get("drgCode"));
        return  "/backend/sdc/docapi/" + "departhome.html";
    }

    /**
     * @Description: 顶部和中部的数据查询
     * @Title: homeData
     */
    @RequestMapping("/departhome/homeData")
    @ResponseBody
    public Object homeData(@RequestParam Map<String, Object> map){
        return sdcHomeIndexService.getHomeData(map);
    }

    /**
     * @Description: 首页下面表格数据
     * @Title: selectAllDepartData
     */
    @RequestMapping("/departhome/selectAllDepartData")
    @ResponseBody
    public Object selectAllDepartData(@RequestParam Map<String, Object> map){
        return sdcHomeIndexService.selectAllDoctorData(map);
    }

    /**
     * 首页点击图例中数字跳转页面
     * @param key
     * @param model
     * @return
     */
    @RequestMapping("/departhome/to_case")
    public String caseKey(@RequestParam Map<String, Object> map,Model model) {
        String key = map.get("key").toString();
        model.addAttribute("key", map.get("key"));
        model.addAttribute("office", map.get("office"));
        model.addAttribute("depart", map.get("depart"));
        model.addAttribute("medicalGroup", map.get("medicalGroup"));
        model.addAttribute("doctor", map.get("doctor"));
        model.addAttribute("drgType", map.get("drgType"));
        model.addAttribute("desc", map.get("desc"));
        if (CommonUtil.equals("drgNum", key)) {
            return "/backend/sdc/docapi/" + "qcEntityDetail.html";
        } else {
            return "/backend/sdc/docapi/" + "qcCaseDetail.html";
        }
    }
    /**
     * 获取触发质控的患者数据
     * @param params
     * @return
     */
    @RequestMapping("/departhome/qcCaseList")
    @ResponseBody
    public Object qcCaseList(@RequestParam Map<String, Object> params) {
        Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
        List<Map<String, Object>> result = sdcHomeIndexService.getQcCaseList(page, params);
        page.setRecords((List<Map<String, Object>>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 获取质控病种的数据
     * @param params
     * @return
     */
    @RequestMapping("/departhome/qcEntityList")
    @ResponseBody
    public Object qcEntityList(@RequestParam Map<String, Object> params) {
        Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
        List<Map<String, Object>> result = sdcHomeIndexService.getQcEntityList(page, params);
        page.setRecords((List<Map<String, Object>>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * @Desc 患者触发质控项页面
     * @param params
     * @param model
     * @return
     * @Author zhouxuan
     * @Date 2022年1月27日 下午3:02:42
     */
    @RequestMapping("/departhome/to_qcDetail")
    public String to_qcDetail(@RequestParam Map<String, Object> params,Model model) {
        model.addAttribute("episodeId",params.get("episodeId"));
        return "/backend/sdc/docapi/" + "qcDetail.html";
    }

    @RequestMapping(value = "/departhome/qcDetailList")
    @ResponseBody
    public Object qcDetailList(@RequestParam Map<String, Object> params) {
        return sdcBusiQcTriggeredService.selectQcDetailList(params);
    }

    /**
     * @Description: HOS门户未上报消息图标
     * @param:       @return
     * @return:      Object
     * @author:      孙英杰
     * @date:        2023年3月27日 上午9:36:43
     */
    @GetMapping("/getNotUpload")
    @ResponseBody
    public Object getNotUpload() {
        DateTime lastDay = new DateTime();
        DateTime firstday = DateUtil.getDateByDay(lastDay, -365);

        Map<String,Object> params = new HashMap<String,Object>();
        params.put("startDate", firstday.toString());
        params.put("endDate", lastDay.toString());
        String[] ar = ArrayUtil.stringToArray("'I','Save','Submit','Check','Back'", ArrayUtil.COMMA);
        params.put("statusList", Arrays.asList(ar));
        List<SdsQcincaseEntity> incaseList = sdsQcincaseService.selectMrList(params);
        Map<String,Object> result = new HashMap<String,Object>();
        result.put("code", "200");
        result.put("data", incaseList.size());
        result.put("msg", "success");
        result.put("success", "true");
        return result;
    }

    @RequestMapping("/sdsloc")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "userId", value = "登陆用户Id", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "wardId", value = "病区Id", required = false, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "locId", value = "科室Id", required = false, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "Role", value = "当前用户的角色类别", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "userName", value = "登陆用户名称", required = true, dataType = "String")
    })
    public String sdsloc(@RequestParam String userId,@RequestParam String wardId,@RequestParam String locId,
                         @RequestParam String Role,@RequestParam String userName, Model model) {
        //获取部门信息
        JSONArray officMap = cdcHospitalService.getOfficeMap();
        //默认加载所有科室
        JSONArray departMap = sdsCommonService.getDepartMap(new HashMap<>());
        //获取病种
        JSONArray entityMap = sdsQcentityService.getUpEntityMap();
        //获取病种的年份
        JSONArray yearMap = sdsQcincaseService.getYearMap();
        //获取病种的月份
        JSONArray monthMap = sdsQcincaseService.getMonthMap();
        model.addAttribute("officeMap",officMap);
        model.addAttribute("departMap",departMap);
        model.addAttribute("entityMap",entityMap);
        model.addAttribute("yearMap",yearMap);
        model.addAttribute("monthMap",monthMap);
        model.addAttribute("userId", userId);
        model.addAttribute("userName", userName);
        model.addAttribute("wardId", wardId);
        model.addAttribute("locId", locId);
        model.addAttribute("Role", Role);
        return PREFIX + "sdsloc.html";
    }

    @RequestMapping("/sdsdoc")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "userId", value = "登陆用户Id", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "wardId", value = "病区Id", required = false, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "locId", value = "科室Id", required = false, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "Role", value = "当前用户的角色类别", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "userName", value = "登陆用户名称", required = true, dataType = "String")
    })
    public String sdsdoc(@RequestParam String userId,@RequestParam String wardId,@RequestParam String locId,
                         @RequestParam String Role,@RequestParam String userName, Model model) {
        //获取部门信息
        JSONArray officMap = cdcHospitalService.getOfficeMap();
        //默认加载所有科室
        JSONArray departMap = sdsCommonService.getDepartMap(new HashMap<>());
        //获取病种的年份
        JSONArray yearMap = sdsQcincaseService.getYearMap();
        //获取病种的月份
        JSONArray monthMap = sdsQcincaseService.getMonthMap();
        model.addAttribute("officeMap",officMap);
        model.addAttribute("departMap",departMap);
        model.addAttribute("yearMap",yearMap);
        model.addAttribute("monthMap",monthMap);
        model.addAttribute("userId", userId);
        model.addAttribute("userName", userName);
        model.addAttribute("wardId", wardId);
        model.addAttribute("locId", locId);
        model.addAttribute("Role", Role);
        return PREFIX + "sdsdoc.html";
    }

    /**
     * @Description: 首次进入单病种质量绩效统计
     * @Title: sdsMsta
     * @author: zhangdc
     * @date:2021-06-27 10:09:15
     */
    @RequestMapping("/sdsmsta")
    public String index(Model model) {
        //获取部门信息
        JSONArray officMap = cdcHospitalService.getOfficeMap();
        //默认加载所有科室
        JSONArray departMap = sdsCommonService.getDepartMap(new HashMap<>());
        //获取病种
        JSONArray entityMap = sdsQcentityService.getUpEntityMap();
        //获取病种的年份
        JSONArray yearMap = sdsQcincaseService.getYearMap();
        //获取病种的月份
        JSONArray monthMap = sdsQcincaseService.getMonthMap();
        model.addAttribute("officeMap",officMap);
        model.addAttribute("departMap",departMap);
        model.addAttribute("entityMap",entityMap);
        model.addAttribute("yearMap",yearMap);
        model.addAttribute("monthMap",monthMap);
        return PREFIX + "sdsmsta.html";
    }

    /**
     * @Description: 单病种病种指标统计
     * @Title: sdsMsta
     * @author: zhangdc
     * @date:2021-06-27 10:09:15
     */
    @RequestMapping("/indexstat")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "userId", value = "登陆用户Id", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "wardId", value = "病区Id", required = false, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "locId", value = "科室Id", required = false, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "Role", value = "当前用户的角色类别", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "userName", value = "登陆用户名称", required = true, dataType = "String")
    })
    public String indexstat(@RequestParam String userId,@RequestParam String wardId,@RequestParam String locId,
                            @RequestParam String Role,@RequestParam String userName, Model model) {
        //获取部门信息
        JSONArray officMap = cdcHospitalService.getOfficeMap();
        //默认加载所有科室
        //JSONArray departMap = cdcLocationService.getDepartMap();
        //加载用户关联科室
        JSONArray departMap = sdsCommonService.getDepartMap(new HashMap<>());
        //获取病种
        JSONArray entityMap = sdsQcentityService.getUpEntityMap();
        model.addAttribute("officeMap",officMap);
        model.addAttribute("departMap",departMap);
        model.addAttribute("entityMap",entityMap);
        model.addAttribute("officeMap",officMap);
        model.addAttribute("departMap",departMap);
        model.addAttribute("userId", userId);
        model.addAttribute("userName", userName);
        model.addAttribute("wardId", wardId);
        model.addAttribute("locId", locId);
        model.addAttribute("Role", Role);
        return PREFIX + "indexstat.html";
    }

    @RequestMapping("/selectSdsLocTable")
    @ResponseBody
    public Object selectSdsLocTable(@RequestParam Map<String, Object> params) {
        // 查询登录用户关联科室
        //List<String> deptIds = sdsCommonService.getDeptIdsBySysUser();
        //params.put("userLinkDepts", deptIds);
        return analysisSdsMstaService.selectSdsLocTable(params);
    }

    @RequestMapping("/toLocCase")
    public String toLocCase(@RequestParam Map<String, Object> map,Model model) {

        model.addAttribute("startDateV", map.get("startDate"));
        model.addAttribute("endDateV", map.get("endDate"));
        model.addAttribute("officeV", map.get("office"));
        model.addAttribute("departV", map.get("depart"));
        model.addAttribute("qcEntityV", map.get("qcEntity"));
        model.addAttribute("desc",map.get("desc"));
        return PREFIX + "loccase.html";
    }

    @RequestMapping("/selectSdsDocTable")
    @ResponseBody
    public Object selectSdsDocTable(@RequestParam Map<String, Object> params) {
        // 查询登录用户关联科室
        //List<String> deptIds = sdsCommonService.getDeptIdsBySysUser();
        //params.put("userLinkDepts", deptIds);
        return analysisSdsMstaService.selectSdsQcDocTable(params);
    }

    @RequestMapping("/to_case")
    public String caseKey1(@RequestParam Map<String, Object> map,Model model) {
        model.addAttribute("key", map.get("key"));
        model.addAttribute("searchType",map.get("searchType"));
        model.addAttribute("startDateV", map.get("startDate"));
        model.addAttribute("endDateV", map.get("endDate"));
        model.addAttribute("officeV", map.get("office"));
        model.addAttribute("departV", map.get("depart"));
        model.addAttribute("qcEntityV", map.get("qcEntity"));
        model.addAttribute("entityId", map.get("entityId"));
        model.addAttribute("desc",map.get("desc") + "列表");
        model.addAttribute("locId",map.get("locId"));
        return PREFIX + "case.html";
    }

    @RequestMapping("/caseList")
    @ResponseBody
    public Object caselist(@RequestParam Map<String, Object> params) {
        // 查询登录用户关联科室
        List<String> deptIds = sdsCommonService.getDeptIdsBySysUser();
        params.put("userLinkDepts", deptIds);
        Page<AnalysisCaseDto> page = new PageFactory<AnalysisCaseDto>().defaultPage();
        List<AnalysisCaseDto> result = this.analysisSdsMstaService.caselist(page,params);
        page.setRecords((List<AnalysisCaseDto>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    @RequestMapping("/to_case2")
    public String caseKey2(@RequestParam Map<String, Object> map,Model model) {
        model.addAttribute("key", map.get("key"));
        model.addAttribute("searchType",map.get("searchType"));
        model.addAttribute("desc",map.get("desc") + "对比");
        model.addAttribute("startDateV", map.get("startDate"));
        model.addAttribute("endDateV", map.get("endDate"));
        model.addAttribute("officeV", map.get("office"));
        model.addAttribute("departV", map.get("depart"));
        model.addAttribute("qcEntityV", map.get("qcEntity"));
        //获取部门信息
        JSONArray officMap = cdcHospitalService.getOfficeMap();
        //默认加载所有科室
        JSONArray departMap = sdsCommonService.getDepartMap(new HashMap<>());
        //获取病种
        JSONArray entityMap = sdsQcentityService.getUpEntityMap();
        model.addAttribute("officeMap",officMap);
        model.addAttribute("departMap",departMap);
        model.addAttribute("entityMap",entityMap);
        return PREFIX + "case2.html";
    }

    @RequestMapping("/selectSdsMstaDepart")
    @ResponseBody
    public Object selectSdsMstaDepart(@RequestParam Map<String, Object> params) {
        // 查询登录用户关联科室
        List<String> deptIds = sdsCommonService.getDeptIdsBySysUser();
        params.put("userLinkDepts", deptIds);
        return analysisSdsMstaService.selectSdsMstaDepart(params);
    }

    /**
     * @Description: 查询单病种指标统计表格数据
     * @Title: selectIndexTableData
     * @return: Object
     * @author: zhangdc
     * @date:2022-03-23 10:09:15
     */
    @RequestMapping("/selectIndexTableData")
    @ResponseBody
    public Object selectIndexTableData(@RequestParam Map<String, Object> params) {
        return analysisSdsIndstaService.selectIndexTableData(params);
    }

    /**
     * @Description: 查询单病种费用/住院日
     * @Title: selectSysSumChart
     * @return: Object
     * @author: zhangdc
     * @date:2022-03-23 10:09:15
     */
    @RequestMapping("/selectSysSumChart")
    @ResponseBody
    public Object selectSysSumChart(@RequestParam Map<String, Object> params) {
        return analysisSdsIndstaService.selectSysSumChart(params);
    }

    /**
     * @Description: 查询单病种质量绩效统计表格
     * @Title: selectSdsMstaTable
     * @return: Object
     * @author: zhangdc
     * @date:2021-06-27 10:09:15
     */
    @RequestMapping("/selectSdsMstaTable")
    @ResponseBody
    public Object selectSdsMstaTable(@RequestParam Map<String, Object> params) {
        // 查询登录用户关联科室
        List<String> deptIds = sdsCommonService.getDeptIdsBySysUser();
        params.put("userLinkDepts", deptIds);
        return analysisSdsMstaService.selectSdsMstaTable(params);
    }

    @RequestMapping("/departhomeLeave")
    public String homeLeave(@RequestParam Map<String, Object> map, Model model) {
        //获取病种
        JSONArray entityMap = sdsQcentityService.getUpEntityMap();

        model.addAttribute("entityMap", entityMap);
        model.addAttribute("departCode", map.get("departCode"));
        model.addAttribute("departDesc", map.get("departDesc"));
        model.addAttribute("drgCode", map.get("drgCode"));
        model.addAttribute("startDate", map.get("startDate"));
        model.addAttribute("endDate", map.get("endDate"));
        return  "/backend/sdc/docapi/" + "departhomeLeave.html";
    }

    /**
     * @Description: 顶部和中部的数据查询
     * @Title: homeData
     */
    @RequestMapping("/departhomeLeave/homeData")
    @ResponseBody
    public Object homeDataLeave(@RequestParam Map<String, Object> map){
        return sdcHomeIndexService.getLeaveHomeData(map);
    }

    /**
     * @Description: 首页下面表格数据
     * @Title: selectAllDepartData
     */
    @RequestMapping("/departhomeLeave/selectAllDepartData")
    @ResponseBody
    public Object selectAllDepartDataLeave(@RequestParam Map<String, Object> map){
        return sdcHomeIndexService.selectLeaveAllDoctorData(map);
    }

    /**
     *
     * @param
     * @param model
     * @return
     */
    @RequestMapping("/departhome/to_caseLeave")
    public String caseKeyLeave(@RequestParam Map<String, Object> map,Model model) {
        String key = map.get("key").toString();
        model.addAttribute("key", map.get("key"));
        model.addAttribute("office", map.get("office"));
        model.addAttribute("depart", map.get("depart"));
        model.addAttribute("medicalGroup", map.get("medicalGroup"));
        model.addAttribute("doctor", map.get("doctor"));
        model.addAttribute("drgType", map.get("drgType"));
        model.addAttribute("desc", map.get("desc"));
        model.addAttribute("startDate", map.get("startDate"));
        model.addAttribute("endDate", map.get("endDate"));
        if (CommonUtil.equals("drgNum", key)) {
            return "/backend/sdc/qcentity/" + "qcLeaveEntityDetail.html";
        } else {
            return "/backend/sdc/qccase/" + "qcLeaveCaseDetail.html";
        }
    }




}
